package com.zyp.dao;


import com.zyp.entity.Phone;
import com.zyp.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class PhoneDao {

    QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

    //需求1:  查询价格高于2000元，生产日期是2019年之前的所有手机
    public List<Phone> checkPhoneSituation(Double price, String prodate) throws SQLException {
        String sql = "SELECT * FROM phone WHERE price>? AND prodate>?";
        Object[] param = {price, prodate};
        List<Phone> phones = qr.query(sql, new BeanListHandler<Phone>(Phone.class), param);
        return phones;
    }

    //需求2:  查询所有颜色是白色的手机信息
    public List<Phone> inquirePhoneColor(String color) throws SQLException {
        String sql = "SELECT * FROM phone WHERE color =?";
        List<Phone> phones = qr.query(sql, new BeanListHandler<Phone>(Phone.class), color);
        return phones;
    }
}
